package com.industrial.governance.service.impl;

import com.industrial.common.core.utils.StringUtils;
import com.industrial.governance.domain.QueryParams;
import com.industrial.governance.domain.TaxRankingResVo;
import com.industrial.governance.mapper.TaxRankingMapper;
import com.industrial.governance.service.ITaxRankingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *     税收排名
 * </p>
 * @author sangguangcan
 */
@Service
public class TaxRankingServiceImpl implements ITaxRankingService {

    @Autowired
    private TaxRankingMapper taxRankingMapper;


    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * 查询亩产税收排名列表
     *
     * @param params
     * @return
     */
    @Override
    public List<TaxRankingResVo> list(QueryParams params) {
        List<TaxRankingResVo> list = taxRankingMapper.list(params);
        for(TaxRankingResVo temp : list){

            StringBuilder areaStr = new StringBuilder();

            String province = temp.getProvince();
            String city = temp.getCity();
            String county = temp.getCounty();

            if(StringUtils.isNotBlank(province)){
                areaStr.append(redisTemplate.opsForValue().get("area:" + province));
            }
            if(StringUtils.isNotBlank(city)){
                areaStr.append(redisTemplate.opsForValue().get("area:" + city));
            }
            if(StringUtils.isNotBlank(county)){
                areaStr.append(redisTemplate.opsForValue().get("area:" + county));
            }
            temp.setArea(areaStr.toString());

        }
        return list;
    }
}
